package easyjava.hibernate.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import easyjava.hibernate.bean.SchoolYear;

public class SchoolYearDao {
	private Session session;
	
	public SchoolYearDao(Session session){
		this.session=session;
	}
	
	public List<SchoolYear> list(){
		Query <SchoolYear> query =session.createQuery("from SchoolYear", SchoolYear.class);
		
		return query.getResultList();
	}
	public void insert(SchoolYear schoolYear) {
		Transaction tx = session.beginTransaction();
		try {

			session.save(schoolYear);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
	}
	public void update(SchoolYear schoolYear){
		Transaction tx = session.beginTransaction();
		try {

			session.update(schoolYear);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
		
	}
	public void delete(SchoolYear schoolYear){
		Transaction tx = session.beginTransaction();
		try {
			
			session.delete(schoolYear);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
	}	

}
